package com.chinasofti.set02;

import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;

public class Test02 {
    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1 , Student o2){
                int result = o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()):result;
                return result;
            }
        });
        //创建学生对象
        Student s1 = new Student("zhangsan",17);
        Student s2 = new Student("lisi",18);
        Student s3 = new Student("wangwu",19);
        Student s4 = new Student("zhaoliu",20);
        Student s5 = new Student("dali",17);

        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);

        for (Student student:ts){
            System.out.println(student);
        }
    }

}
